Page({
  data: {
    tabs: [{
        id: 0,
        value: "体验问题",
        isActive: true
      },
      {
        id: 1,
        value: "商品、商家投诉",
        isActive: false
      }
    ],
    //被选中的图片路径数组
    chooseImg: [],
    //文本域得值
    textValue: ""
  },
  handletabsItemChange(e) {
    //获取被点击的标题索引
    const {
      index
    } = e.detail;
    //修改原数组
    let {
      tabs
    } = this.data;
    tabs.forEach((e, i) => {
      i === index ? e.isActive = true : e.isActive = false
    });
    this.setData({
      tabs
    })
  },
  //点击加号添加图片
  handleChooseImg() {
    wx.chooseImage({
      count: 9,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: (result) => {
        this.setData({
          //图片数组应该进行拼接
          chooseImg: [...this.data.chooseImg, ...result.tempFilePaths]
        })

      }
    });
  },
  handleRemoveImg(e) {
    //获取被点击的组件的索引
    const {
      index
    } = e.currentTarget.dataset;
    let {
      chooseImg
    } = this.data;
    chooseImg.splice(index, 1);
    this.setData({
      chooseImg
    })
  },
  bindTextInput(e) {
    this.setData({
      textValue: e.detail.value
    })
  },
  handleFormSubmit() {
    //获取文本域内容
    const {
      textValue,
      chooseImg
    } = this.data;
    if (!textValue.trim()) {
      //不合法
      wx.showToast({
        title: '输入不合法',
        icon: 'none',
        image: '',
        mask: true
      });
      return;
    };
    //准备上传图片到专门的图片服务器
    //上传文件的api不支持多个文件同时上传，需要遍历图片数组  挨个上传 然后自己在维护图片数组
    chooseImg.forEach((ele, i) => {
      wx.uploadFile({
        url: '',
        // filePath: ,
        // name: ,
        formData: {},
        success: (result) => {

        },
        fail: () => {},
        complete: () => {}
      });
    });
  }
})